package pro.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pro.spring.inter.InformationMapper;
import pro.spring.model.Information;
import pro.spring.vo.PaginationVo;

@Service
public class InformationService{

	@Autowired
	private InformationMapper InformationMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return InformationMapper.deleteByPrimaryKey(id);
	}

	public int insert(Information record) {
		return InformationMapper.insert(record);
	}
	
	public int selectByPrimaryKeytwo(Integer id){
		return InformationMapper.selectByPrimaryKeytwo(id);
	}

	public Information selectByPrimaryKey(Integer id) {
		return InformationMapper.selectByPrimaryKey(id);
	}
	
	public Integer selectMaxIdByType(Integer inType){
		return InformationMapper.selectMaxIdByType(inType);
	}
	
	public Integer selectMinIdByType(Integer inType){
		return InformationMapper.selectMinIdByType(inType);
	}

	public int updateByPrimaryKey(Information record) {
		return InformationMapper.updateByPrimaryKey(record);
	}
	
	//文章
	public PaginationVo<Information> getPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Information> pageVo=new PaginationVo<Information>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(InformationMapper.getCountByType(100));
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(InformationMapper.selectListPageByType(100,pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
	
	public PaginationVo<Information> getAllPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Information> pageVo=new PaginationVo<Information>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(InformationMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(InformationMapper.selectListPage(pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
	
	public PaginationVo<Information> getAllPaginationInfoByKey(String key,int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Information> pageVo=new PaginationVo<Information>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(InformationMapper.selectCountByKey(key));
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(InformationMapper.selectListPageByKey(key,pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
	
	public PaginationVo<Information> selectArtListPageByType(int inType,int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Information> pageVo=new PaginationVo<Information>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(InformationMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(InformationMapper.selectArtListPageByType(inType,pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
}
